package com.sky.financelake.helper;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import redis.clients.jedis.Jedis;

public class RedisHelper {

    private static RedisHelper instance;
    private static Jedis jedis;

    private RedisHelper() {
    }

    public void initJedis() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String url = "redis://:123456@1.116.131.137:6379/1";
                try {
                    URI uri = new URI(url);
                    jedis = new Jedis(uri);
                } catch (Exception e) {
                    System.out.println(e.getLocalizedMessage());
                }
            }
        }).start();

    }

    public static RedisHelper getInstance() {
        if (instance == null) {
            if (instance == null) {
                instance = new RedisHelper();
            }
        }
        return instance;
    }

    public static Map hgetAll(String key) {
        Map map =  jedis.hgetAll(key);
        return map;
    }

}
